/**
 * 智能版本核心管理器
 */
class VersionCore {
  private static instance: VersionCore;
  private versions: Map<string, string> = new Map();
  private currentCore = 'latest';

  private constructor() {
    this.initVersions();
  }

  public static getInstance(): VersionCore {
    if (!VersionCore.instance) {
      VersionCore.instance = new VersionCore();
    }
    return VersionCore.instance;
  }

  private initVersions() {
    // 自动检测可用版本
    this.versions.set('core', 'v2');
    this.versions.set('adapters', 'v2');
    this.versions.set('platform', 'v1');
    this.versions.set('wasm', 'v1');
  }

  /**
   * 获取模块的最新兼容版本
   */
  public getCompatibleVersion(module: string): string {
    return this.versions.get(module) || 'v1';
  }

  /**
   * 动态升级核心版本
   */
  public upgradeCoreVersion(module: string, version: string) {
    this.versions.set(module, version);
    this.currentCore = this.detectLatestCore();
  }

  private detectLatestCore(): string {
    // 实现智能检测最新核心版本的逻辑
    return Array.from(this.versions.values())
      .sort()
      .pop() || 'latest';
  }
}

export const versionCore = VersionCore.getInstance();